<template>
  <div>
    <el-dialog title="房产分类" :append-to-body="true" @close="closeDio" :visible="dialogTableVisible" width="1000px" style="padding:20px">
      <div>
        <div v-for="(item, index) in shopsList" :key="index" class="box-menu">
          <p style=" margin-bottom: 24px;" @click="addShops(item)">
            {{ item.title }}(一级)
          </p>
          <div v-if="item.z && isShopCate" class="box-menu-1">
            <div v-for="(it, i) in item.z" :key="i" class="sa">
              <p @click="addShops(it)">{{ it.title }} (二级)</p>
              <span v-if="it.z" @click="showActive(it.id)"
                  :style="{ color: active == it.id ? 'red' : '#ddd' }">[{{ active == it.id ? "-" : "+" }}]</span>
              <!-- {{i%1}}{{i%2}}{{i%3}}{{i%4}} -->
              <div v-if="it.z" class="box-menu-1" style="width: 980px;background: #f9f9f9;margin-left: -20px;padding: 0 20px;" :style="{
                  left: toZhuanhuan(i),
                  marginTop: active == it.id ? '14px' : '0'
                }">
                <div v-for="(its, is) in it.z" class="box-menu-2" :key="is" :class="{ activeMenu: active == its.parent_id }">
                  <p style=" margin: 12px 0 12px;" @click="addShops(its)">
                    {{ its.title }} (三级)
                  </p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "xznewscate",
  props: {
    show: {
      type: Boolean,
      default: true
    },
    showType: {
      type: String,
      default: "table"
    }
  },
  data () {
    return {
      shopsList: [],
      dialogTableVisible: this.show,
      loading: false
    };
  },
  methods: {
    toZhuanhuan (i) {
      if (i % 4) {
        return -((i % 4) * 235) + "px";
      }
    },
    showActive (id) {
      if (this.active == id) {
        this.active = -1;
      } else {
        this.active = id;
      }
    },
    addShops (row) {
      row.url_title = "房产分类";
      this.$emit("sendShop", row);
      this.dialogTableVisible = false;
    },

    closeDio () {
      this.$emit("isshow", false);
      this.dialogTableVisible = false;
    },
    getMaterial () {
      this.loading = true;
      var params = {};
      params.parent_id = "0";
      this.$api.getEstate.getEstateCateTreeList(params).then(res => {
        if (res.data.code == 200) {
          console.log(res);
          this.shopsList = res.data.result;
        }
        this.loading = false;
      });
    }
  },
  watch: {
    show (val1, val2) {
      if (val1 == val2) {
        return;
      }
      this.getMaterial();
      this.dialogTableVisible = val1;
      this.currentPage1 = 1;
    },
    dialogTableVisible (val1, val2) {
      if (val1 == val2) {
        return;
      }
      this.$emit("isshow", val1);
    }
  },
  computed: {},
  mounted () {
    this.getMaterial();
  }
};
</script>
<style lang="less" scoped>
.cate_product {
  display: flex;
  flex-wrap: wrap;
  > li {
    width: 25%;
    // height: 30px;
    line-height: 30px;
    cursor: pointer;
  }
  p:hover {
    color: red;
  }
}
.sa {
  margin-bottom: 24px;
}
.box-menu {
  margin-bottom: 24px;
  p {
    display: inline-block;
    min-width: 168px;
    padding: 0 10px;
    height: 42px;
    line-height: 42px;
    border-radius: 5px;
    background: #f5f5f5;
    text-align: center;
    // margin-bottom: 24px;
    cursor: pointer;
  }
  span {
    color: #a3a3a3;
    margin-left: 12px;
    cursor: pointer;
  }
}
.box-menu-1 {
  display: flex;
  flex-wrap: wrap;
  transition: all 0.3s linear;
  position: relative;
  > div {
    width: 25%;
  }
}
.box-menu-2 {
  width: 940px;
  transition: all 0.3s linear;
  max-height: 0;
  overflow: hidden;
}
.activeMenu {
  max-height: 500px;
}
</style>
